package com.zgy.service.impl;

import com.zgy.dao.UserDao;
import com.zgy.pojo.Dept;
import com.zgy.pojo.User;
import com.zgy.service.UserService;
import com.zgy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class UserServiceImp implements UserService{
    @Autowired
    UserDao dao;

    @Override
    public void update(User user) {
        dao.update(user);
    }

    @Override
    public List<User> query(User user) {
        return dao.query(user);
    }

    @Override
    public List<Dept> dept() {
        return dao.dept();
    }

    @Override
    public void add(User user) {
        dao.add(user);
    }

    @Override
    public User one(User user) {
        return dao.one(user);
    }

    @Override
    public List<Dept> queryDept(Dept dept) {
        return dao.queryDept(dept);
    }

    @Override
    @Transactional
    public void delDept(Dept dept) {
      //删除部门下的所有员工
        dao.delUserByDept(dept);
        //System.out.println(1/0);
        //删除部门
        dao.delDept(dept);
    }
    @Override
    @Transactional
    public void delUser(Integer id) {
        //删除员工
        dao.delUser(id);
    }


    @Override
    public int countUser(User user) {
        return dao.countUser(user);
    }

    @Override
    public List<User> queryPage(Page page, User user) {
        return dao.queryPage(page,user);
    }
}
